
package sumo.box;


import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;


public class MenuJogo extends BasicGameState {
    
    int ident = 0;
    
    
    Image back = null;
    Image sound = null;
    Image nosound = null;
    Image music = null;
    Image nomusic = null;
    Image voltar = null;
    Image restart = null;
    Image scores = null;
    Image menu = null;
  
    
    float sound_scale = 1;
    float music_scale = 1;
    float voltar_scale = 1;
    float restart_scale = 1;
    float scores_scale = 1;
    float menu_scale = 1;
    
    float scaleStep = 0.001f;
    
    
    public MenuJogo(int id) {
        this.ident = id;
    }
    
    @Override
    public int getID() {
        return ident;
    }

    @Override
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        back = new Image("src/IMAGES/menufundo.png");
        Image options = new Image("src/IMAGES/menujogo.png");
        nosound = new Image("src/IMAGES/nosound.png");
        nomusic = new Image("src/IMAGES/nomusic.png");
        
        sound = options.getSubImage(0, 0, 100, 50);
 
        
        music = options.getSubImage(100, 0, 100, 50);
        
        voltar = options.getSubImage(0,50,200,50);
        restart = options.getSubImage(0,100,200,50);
        scores = options.getSubImage(0,150,200,50);
        menu = options.getSubImage(0,200,200,50);
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics grphcs) throws SlickException {
        back.draw(0,0);
        if(!Box.isSound()){
            nosound.draw(180,130,sound_scale);
        }else{
            sound.draw(180,130,sound_scale);
        }
        if(!Box.isMusic()){
            nomusic.draw(280,130,music_scale);
        }else{
            music.draw(280,130,music_scale);
        }
        voltar.draw(180,180,voltar_scale);
        restart.draw(180,230,restart_scale);
        scores.draw(180,280,scores_scale);
        menu.draw(180,330,menu_scale);
    }
    
    
    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException {
        
        Input input = gc.getInput();
        
        if(input.isKeyPressed(Input.KEY_ESCAPE)) {
            sbg.enterState(Box.getFaseAtual());
        }
        int mouseX = input.getMouseX();
        int mouseY = input.getMouseY();
        
        boolean insideSound = false;
        boolean insideMusic = false;
        boolean insideVoltar = false;
        boolean insideRestart = false;
        boolean insideScores = false;
        boolean insideMenu = false;
        
        if( (mouseX >= 180 && mouseX < 180 + sound.getWidth()) && (mouseY >= 130 && mouseY < 130 + sound.getHeight()) ) {
            insideSound = true;
        }
        else if( (mouseX >= 280 && mouseX < 280 + music.getWidth()) && (mouseY >= 130 && mouseY < 130 + music.getHeight()) ) {
            insideMusic = true;
        }
        else if( (mouseX >= 180 && mouseX < 180 + voltar.getWidth()) && (mouseY >= 180 && mouseY < 180 + voltar.getHeight()) ) {
            insideVoltar = true;
        }
        else if( (mouseX >= 180 && mouseX < 180 + restart.getWidth()) && (mouseY >= 230 && mouseY < 230 + restart.getHeight()) ) {
            insideRestart = true;
        }
        else if( (mouseX >= 180 && mouseX < 180 + scores.getWidth()) && (mouseY >= 280 && mouseY < 280 + scores.getHeight()) ) {
            insideScores = true;
        }
        else if( (mouseX >= 180 && mouseX < 180 + menu.getWidth()) && (mouseY >= 330 && mouseY < 330 + menu.getHeight()) ) {
            insideMenu = true;
        }

        
        
        if(insideSound) {
              if(sound_scale < 1.05f) {
                  sound_scale += scaleStep;
              }
              if ( input.isMousePressed(Input.MOUSE_LEFT_BUTTON) ) {
                  if(Box.isSound()){
                      Box.sound();
                      
                  }
                  else{
                      Box.sound();
                      Box.clickSound();
                  }
              }
        }
        else {
            if(sound_scale > 1.0f) {
            sound_scale -= scaleStep;
            } 
        } 
        
        
        
        if(insideMusic) {
              if(music_scale < 1.05f) {
                  music_scale += scaleStep;
              }
              if ( input.isMousePressed(Input.MOUSE_LEFT_BUTTON) ) {
                  Box.clickSound();
                  Box.music();
                  
              }
        }
        else {
            if(music_scale > 1.0f) {
            music_scale -= scaleStep;
            } 
        }         
        
        if(insideVoltar) {
              if(voltar_scale < 1.05f) {
                  voltar_scale += scaleStep;
              }
              if ( input.isMousePressed(Input.MOUSE_LEFT_BUTTON) ) {
                  Box.clickSound();
                  sbg.enterState(Box.getFaseAtual());
              }
        }
        else {
            if(voltar_scale > 1.0f) {
            voltar_scale -= scaleStep;
            } 
        }         
        
        
        //se clica em restart, reinicia o mesmo level
        if(insideRestart) {
              if(restart_scale < 1.05f) {
                  restart_scale += scaleStep;
              }
              if ( input.isMousePressed(Input.MOUSE_LEFT_BUTTON) ) {
                  Box.clickSound();
                  gc.reinit();
                  sbg.enterState(Box.getFaseAtual());
              }
        }
        else {
            if(restart_scale > 1.0f) {
            restart_scale -= scaleStep;
            } 
        }         
           
        // se clica nos scores, vai para a tela de socres.. OK
        if(insideScores) {
              if(scores_scale < 1.05f) {
                  scores_scale += scaleStep * i;
              }
              if ( input.isMousePressed(Input.MOUSE_LEFT_BUTTON) ) {
                  Box.clickSound();
                  sbg.enterState(Box.SCORESSTATE);
              }
        }
        else {
            if(scores_scale > 1.0f) {
            scores_scale -= scaleStep;
            } 
        }
        //se clicar em sair, sair.. OK
        if(insideMenu) {
              if(menu_scale < 1.05f) {
                  menu_scale += scaleStep;
              }
              if ( input.isMousePressed(Input.MOUSE_LEFT_BUTTON) ) {
                  Box.clickSound();
                  sbg.enterState(Box.MENUSTATE);
                  gc.reinit();
              }
        }
        else {
            if(menu_scale > 1.0f) {
            menu_scale -= scaleStep;
            } 
        }
        
    }
    
}
